package com.zr.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebFilter(urlPatterns = { "/admin.html","/aMsg.html","/aRestaurant.html","/aUser.html"})
public class adminFilter implements Filter {
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		HttpSession session=((HttpServletRequest)request).getSession();
		String uid=(String) session.getAttribute("uid");
		String pwd=(String) session.getAttribute("pwd");
		if(uid!=null&&uid.equals("admin")&&pwd!=null&&pwd.equals("admin")) {
			chain.doFilter(request, response);
		}else {
			((HttpServletResponse)response).sendRedirect("adminLogin.html");
		}

	}

	public void destroy() {
		
	}
	public void init(FilterConfig fConfig) throws ServletException {
		
	}

}
